home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d963.lha / SIOD / scm / tree-imper.scm < prev    next >
Text File  |  1999-12-31  |  1KB  |  29 lines

  1. (define (pre-ord tree)
  2.         (define pila (make-pila))
  3.         (define out '())
  4.         (do ()
  5.             ((and (empty-tree? tree) (empty-pila? pila))
  6.              (reverse out))
  7.             (if (empty-tree? tree)
  8.                 (begin (set! tree (top pila))
  9.                        (pop! pila))
  10.                 (begin (set! out (cons (entry tree) out))
  11.                        (push! (right-branch tree) pila)
  12.                        (set! tree (left-branch tree))))))
  13.  
  14. (define (in-ord tree)
  15.         (define pila (make-pila))
  16.         (define out '())
  17.         (do ()
  18.             ((and (empty-tree? tree) (empty-pila? pila))
  19.              (reverse out))
  20.             (if (empty-tree? tree)
  21.                 (let ((p (top pila)))
  22.                      (set! out (cons (car p) out))
  23.                      (set! tree (cdr p))
  24.                      (pop! pila))
  25.                 (begin (push! (cons (entry tree) 
  26.                                     (right-branch tree))
  27.                               pila)
  28.                        (set! tree (left-branch tree))))))
  29.